package com.whfc.cncit.helmet.processor;

import com.alibaba.fastjson.JSON;
import com.whfc.cncit.constant.CncitConst;
import com.whfc.cncit.entity.CncitUpMsgPSA;
import com.whfc.common.constant.QueueConst;
import com.whfc.emp.dto.AppBroadcastRecordEmpDTO;
import com.whfc.emp.enums.AppBroadcastSendState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : qzexing
 * @version : 1.0
 * @date : 2020/7/1 18:05
 */
@Component
public class HelmetUpMsgProcessorPSA implements CncitUpMsgProcessor<CncitUpMsgPSA> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Override
    public void processMsg(CncitUpMsgPSA msg) {
        logger.info("msg:{}", msg);
        if (CncitConst.CMD_TTSD.equals(msg.getType())) {
            //语音播放响应
            AppBroadcastRecordEmpDTO empDTO = new AppBroadcastRecordEmpDTO();
            empDTO.setCode(msg.getDeviceCode());
            empDTO.setState(AppBroadcastSendState.CONFIRM.getValue());
            try {
                amqpTemplate.convertAndSend(QueueConst.EMP_HELMET_BOARDCAST_STATE, JSON.toJSONString(empDTO));
            } catch (Exception e) {
                logger.warn("发送消息失败.", e);
            }
        }
    }
}
